def init_test_member(engine):


    from mall.models.member import Member
    import random
    from mall.models.resource import Resource
    from mall.models.account import Account
    from mall.models.currency import Currency
    member_table = Member.__table__
    account_table = Account.__table__

    conn = engine.connect()
    conn.execute(member_table.delete())
    conn.execute(account_table.delete())

    from sqlalchemy.sql import select
    resource_result = conn.execute(select([Resource]))
    resource_ids = [c[0] for c in resource_result]

    result = conn.execute(select([Currency]))

    currency_ids = [c[0] for c in result]
    for i in range(0, 9):
        account_id = '1-{}'.format(str(i).zfill(15))
        conn.execute(account_table.insert(),
                     id=account_id,
                     balance=random.randrange(1, 100),
                     pending_amount=random.randrange(0, 20),
                     frozen_amoutn=random.randrange(0, 200),
                     reward_amount=random.randrange(0, 100)
                     )
        member_id = 'member_{}'.format(i)
        conn.execute(member_table.insert(),
                     id=member_id,
                     account_id=account_id,
                     screen_name=member_id,
                     currency_id=random.choice(currency_ids),
                     seller_score=random.choice(range(1, 5)),
                     buyer_score=random.choice(range(1, 5)),
                     head_image_id=random.choice(resource_ids),
                     deal_count=random.randint(1000, 99999)
                     )



        # session.query(Member).delete()
        # session.query(Account).delete()
        # resource_list = session.query(Resource).all()
        # currency_list = session.query(Currency).all()
        # for i in range(0, 9):
        #     member_id = 'dealer_{}'.format(i)
        #
        #     member = Member(
        #         id=member_id,
        #         screen_name=member_id,
        #         deal_count=random.randint(1000, 99999),
        #         seller_score=random.choice(range(1, 5)),
        #         buyer_score=random.choice(range(1,5)),
        #         head_image_id=random.choice(resource_list).id,
        #     )
        #
        #     account_id = '1-{}'.format(str(i).zfill(15))
        #
        #     account = Account(
        #         id=account_id,
        #         balance=0,
        #         reward_amount=0,
        #         frozen_amount=0,
        #         pending_amount=0,
        #         currency_id=random.choice(currency_list).id
        #     )
        #     member.account = account
        #
        #     session.add(member)
        # session.commit()
